package za.org.jcicada.genss.sensor.impl;

/**
 * SensorAcceptListener.java
 *
 * @author Simon Cross
 *
 * Created on February 6, 2009, 10:30
 */

import za.org.jcicada.comms.IConnection;
import za.org.jcicada.comms.IKatcpSerializerStrategy;
import za.org.jcicada.comms.IMessageListener;
import za.org.jcicada.comms.impl.AcceptListenerBase;
import za.org.jcicada.genss.sensor.ISensorSubject;
import za.org.jcicada.genss.sensor.katcp.SensorKatcpSerializer;

/**
 * Katcomms accept listener that accepts connections and ties them to
 * a given ISensorSubject.
 */
public class SensorAcceptListener extends AcceptListenerBase {

    /**
     * ISensorSubject implementation to delegate requests to.
     */
    protected ISensorSubject sensorSubject;

    /**
     * Create an accept listener that listens for clients and passes
     * messages through to the given ISensorSubject implementation.
     */
    public SensorAcceptListener(ISensorSubject sensorSubject) {
        this.sensorSubject = sensorSubject;
    }

    /**
     * Create message listeners for new connections.
     * Implements abstract method from AcceptListenerBase.
     *
     * @param connection  New connection from client.
     */
    public IMessageListener createListener(IConnection connection) {
        return new SensorMessaging(connection, sensorSubject);
    }

	@Override
	public IKatcpSerializerStrategy getKatcpSerializerStrategy() {
		return new SensorKatcpSerializer();
	}

}
